function init(){
	var orderId = GetQueryString("id");
	loadTitle(orderId);
	loadProduct(orderId);
	loadDelivery(orderId);
	loadOutBound(orderId);
}

/**
 * 加载头部信息
 */
function loadTitle(orderId){
	$.ajax({
		type:"POST",
		url:path +"/orderlang/order/orderDetailForTitle",
		data:{orderId:orderId},
		success:function(data){
			var list = data.rows;
			if(list != null){
				var html = "";
				html += "<p>订单号：<span>"+list.orderCode+"</span></p>";
				html += "<p>客户名称：<span>"+list.userId+"</span></p>";
				html += "<p>订单金额：<span>"+list.amount+"</span></p>";
				var orderState;
				if(list.orderState == 1){
					orderState = '已关闭';
				}else{
					orderState = '处理中';
				}
				var paymentState;
				if(list.paymentState == 1){
					paymentState = '已结清';
				}else{
					paymentState = '付款中';
				}
				html += "<p>订单状态：<span>"+orderState+"</span></p>";
				html += "<p>付款状态：<span>"+paymentState+"</span></p>";
				html += "<p>订单日期：<span>"+list.orderTime+"</span></p>";
				$('.content').find('.order-number').html(html);
			}
		},
		error: function(){
			layer.msg('加载头部信息失败！',{icon:5,time:1000});
		}
	});
}

/**
 * 商品列表
 */
function loadProduct(orderId){
	$.ajax({
		type:"POST",
		url:path +"/orderlang/orderProduct/orderDetailForProduct",
		data:{orderId:orderId},
		success:function(data){
			if(data.state == 1){
				var list = data.data;
				var html = "";
				for(var i=0; i<list.length; i++){
					var comment = list[i];
					html += "<tr>";
					html += "<td><img src='"+comment.imgUrl+"' alt=''/></td>";
					html += "<td><a href='#'>"+comment.productName+"</a></td>";
					html += "<td>";
					var productSpecs = comment.sepcList;
					for(var j=0; j<productSpecs.length; j++){
						var productSpec = productSpecs[j];
						html += productSpec.specName+":&nbsp;&nbsp;"+productSpec.specValue+";&nbsp;&nbsp;";
					}
					html += "</td>";
					html += "<td>"+comment.orderQuantity+"</td>";
					html += "<td>"+comment.outboundQuantity+"</td>";
					html += "<td>"+(comment.orderQuantity-comment.outboundQuantity)+"</td>";
					html += "<td></td></tr>";
				}
				$('.productTable').find('tbody').html(html);
			}
		},
		error: function(){
			layer.msg('加载商品信息失败！',{icon:5,time:1000});
		}
	});
}

/**
 * 加载发货单列表
 */
function loadDelivery(orderId){
	$.ajax({
		type:"POST",
		url:path +"/delivery/orderDetailForDelivery",
		data:{orderId:orderId},
		success:function(data){
			if(data){
				var html = "";
				for(var i=0; i<data.length; i++){
					var comment = data[i];
					html += "<tr>";
					html += "<td><a href='#'>"+comment.deliveryCode+"</a></td>";
					html += "<td>"+comment.createTime+"</td>";
					if(comment.approve == 2){
						html += "<td><p class='state c2021'>审批驳回</p></td>";
					}else if(comment.approve == 1){
						html += "<td><p class='state c2019'>审批通过</p></td>";
					}else{
						html += "<td><p class='state c2017'>未审批</p></td>";
					}
					if(comment.status == 2){
						html += "<td><p class='state c2019'>发货完成</p></td>";
					}else if(comment.status == 1){
						html += "<td><p class='state c2020'>发货中</p></td>";
					}else{
						html += "<td><p class='state c2018'>未发货</p></td>";
					}
					html += "<td></td></tr>";
				}
				$('.sendOrderTable').find('tbody').html(html);
			}
		},
		error: function(){
			layer.msg('加载发货单信息失败！',{icon:5,time:1000});
		}
	});
}

/**
 * 加载出库单列表
 */
function loadOutBound(orderId){
	$.ajax({
		type:"POST",
		url:path +"/outbound/orderDetailForOutbound",
		data:{orderId:orderId},
		success:function(data){
			if(data){
				var html = "";
				for(var i=0; i<data.length; i++){
					var comment = data[i];
					html += "<tr>";
					html += "<td><a href='#'>"+comment.outboundCode+"</a></td>";
					html += "<td>"+comment.outboundTime+"</td>";
					html += "<td>"+comment.transportMode+"</td>";
					html += "<td>"+comment.contactName+"</td>";
					html += "<td>"+comment.tel+"</td>";
					html += "<td></td></tr>";
				}
				$('.outboundTable').find('tbody').html(html);
			}
		},
		error: function(){
			layer.msg('加载出库单信息失败！',{icon:5,time:1000});
		}
	});
}

function GetQueryString(name){
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]);
    return null;
}

init();